/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.cms.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.cms.entity.CampusinfoAboutUs;
import com.lczyfz.campusinfo.modules.cms.service.CampusinfoAboutUsService;

/**
 * 关于我们Controller
 * @author 陈维乾
 * @version 2018年4月19日
 */
@Controller
@RequestMapping(value = "${adminPath}/cms/aboutus/campusinfoAboutUs")
public class CampusinfoAboutUsController extends BaseController {

	@Autowired
	private CampusinfoAboutUsService campusinfoAboutUsService;
	
	@ModelAttribute
	public CampusinfoAboutUs get(@RequestParam(required=false) String id) {
		CampusinfoAboutUs entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoAboutUsService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoAboutUs();
		}
		return entity;
	}
	
	@RequiresPermissions("cms:aboutus:campusinfoAboutUs:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoAboutUs campusinfoAboutUs, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoAboutUs> page = campusinfoAboutUsService.findPage(new Page<CampusinfoAboutUs>(request, response), campusinfoAboutUs); 
		model.addAttribute("page", page);
		return "modules/cms/campusinfoAboutUsList";
	}

	@RequiresPermissions("cms:aboutus:campusinfoAboutUs:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoAboutUs campusinfoAboutUs, Model model) {
		model.addAttribute("campusinfoAboutUs", campusinfoAboutUs);
		return "modules/cms/campusinfoAboutUsForm";
	}

	@RequiresPermissions("cms:aboutus:campusinfoAboutUs:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoAboutUs campusinfoAboutUs, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoAboutUs)){
			return form(campusinfoAboutUs, model);
		}
		campusinfoAboutUsService.save(campusinfoAboutUs);
		addMessage(redirectAttributes, "保存关于我们成功");
		return "redirect:"+Global.getAdminPath()+"/cms/aboutus/campusinfoAboutUs/?repage";
	}
	
	@RequiresPermissions("cms:aboutus:campusinfoAboutUs:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoAboutUs campusinfoAboutUs, RedirectAttributes redirectAttributes) {
		campusinfoAboutUsService.delete(campusinfoAboutUs);
		addMessage(redirectAttributes, "删除关于我们成功");
		return "redirect:"+Global.getAdminPath()+"/cms/aboutus/campusinfoAboutUs/?repage";
	}

}